﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>机构管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link href="/lobsteruiframe/layuiadmin/layui/css/layui.css" rel="stylesheet" />
    <link href="/lobsteruiframe/layuiadmin/style/admin.css" rel="stylesheet" />
    <script src="/lobsteruiframe/layuiadmin/layui/layui.js"></script>
    <script src="/jslib/jquery-3.4.1.min.js"></script>
    <script src="/jslib/lobster.js"></script>
</head>
<body>
    <div class="layui-fluid">
        <form class="layui-form">
            <div class="layui-card">
                <div class="layui-card-body">

                    <table class="layui-table" id="gridWorkers" lay-filter="gridWorkers"></table>
                </div>

            </div>
        </form>
    </div>
</body>
</html>
<script type="text/javascript">
    lobsterlayui.main(['index', 'layer', 'form', 'element', 'upload'], {
        data: {
            $layui: null,
            right: null,
            tablework: null,
        },
        pageload: function (right) {
            this.data.right = right;
            this.data.tablework = this.loadtableworkers();
            this.initevent();
        },
        initevent() {
            var self = this;
            var table = layui.table;
            table.on("toolbar(gridWorkers)", function (obj) {
                var data = obj.data;
                // 添加机构
                if (obj.event == "add-submit") {
                    self.addworker();
                    return false;
                }
            });

            // 监听行工具事件 
            table.on("tool(gridWorkers)", function (obj) {
                var data = obj.data;
                var event = obj.event;
                if (event === "disable" || event === "enable") {
                    self.stopworker(data);
                } else if (event === "alter") {
                    self.alterworker(data);
                } else if (event == "alterstyle") {
                    self.alterstyle(data);
                }
            });
        },
        loadtableworkers() {
            var table = layui.table;
            return table.render({
                elem: "#gridWorkers",
                headers: lobsterlayui.GetHeaderData(),
                where: {
                },
                height: "full-80",
                cellMinWidth: 80, 
                toolbar: "#barWorkers",
                url: "/admin/v1/worker/GetMyWorkerData", //数据接口 
                page: true, //开启分页 
                //size: "sm",
                //even: true,
                loading: true,
                cols: [[ //表头 
                    { field: "WorkId", width: "10%", title: "机构ID" },
                    { field: "WorkNo", width: "15%", title: "机构代码" },
                    { field: "WorkName", width: "15%", title: "机构名称" },
                    { field: "RegKey", width: "20%", title: "注册码" },
                    { field: "WorkType", width: "10%", title: "机构类型", templet: "#barRowWorkType" },
                    { field: "Memo", width: "10%", title: "备注" },
                    { field: "States", width: "5%", title: "状态标识", templet: "#barRowStates" },
                    { title: "操作", width: "15%", align: 'center', toolbar: "#barRowWorkers", fixed: "right" }
                ]],
                parseData: function (res) {
                    return {
                        code: res.code,
                        msg: res.msg,
                        count: res.data.count,
                        data: res.data.workerList
                    }
                }
            });
        },
        addworker() {
            var self = this;
            layer.open({
                type: 1,
                title: "添加机构信息",
                btn: ["保存", "取消"],
                btnAlign: "r",
                content: $('#dlg_workerform').html(),
                area: ["80%", "80%"],
                maxmin: true,
                btn2: function (index, layero) {
                    $("#LAY-work-form-reset").trigger('click');
                }
                , cancel: function () {
                    $("#LAY-work-form-reset").trigger('click');
                },
                success: function (layero, index) {
                    $("#txtWorkNo").removeAttr("disabled");

                },
                yes: function (index, layero) {
                    var submit = $('#btnSubmit');
                    layui.form.on('submit(btnSubmit)', function (formdata) {
                        self.saveworker(formdata);
                    });
                    submit.trigger("click");
                }
            });
        },
        alterworker(data) {
            var self = this;
            layer.open({
                type: 1,
                title: "添加机构信息",
                btn: ["保存", "取消"],
                btnAlign: "r",
                content: $('#dlg_workerform').html(),
                area: ["80%", "80%"],
                maxmin: true,
                btn2: function (index, layero) {
                    $("#LAY-work-form-reset").trigger('click');
                }
                , cancel: function () {
                    $("#LAY-work-form-reset").trigger('click');
                },
                success: function (layero, index) {
                    $("#txtWorkNo").attr("disabled", true);
                    var workid = data.WorkId;
                    lobsterlayui.GET('/admin/v1/worker/GetWorkerDetails', { workid: workid }).then(data => {
                        layui.form.val('formWorkers', data['worker']);
                    });
                },
                yes: function (index, layero) {
                    var submit = $('#btnSubmit');
                    layui.form.on('submit(btnSubmit)', function (formdata) {
                        self.saveworker(formdata);
                    });
                    submit.trigger("click");
                }
            });
        },
        alterstyle(rowdata) {
            var self = this;
            layer.open({
                type: 1,
                title: "编辑机构样式",
                btn: ["保存", "取消"],
                btnAlign: "r",
                content: $('#dlg_workerstyles').html(),
                area: ["1000px", "565px"],
                maxmin: true,
                success: function (layero, index) {
                    $("#textWorkId").val(rowdata.WorkId);
                    var load = layer.msg('正在处理，请稍候', { icon: 16, time: 0, shade: [0.3, '#393D49'] });
                    lobsterlayui.GET('/admin/v1/worker/GetWorkerStyles', { workId: rowdata.WorkId }).then(data => {
                        layer.close(load);
                        self.InitUpload();
                        data = data["datastyle"];
                        layui.form.val("formWorkerStyles", data);
                        if (data.PatientLogo)
                            $("#patientLogo").attr("src", data.PatientLogo);
                        if (data.DoctorLogo)
                            $("#doctorLogo").attr("src", data.DoctorLogo);
                        if (data.OpenTopLogo) {
                            $("#openTopLogo").attr("src", data.OpenTopLogo)
                        }
                        if (data.BgImage) {
                            $("#bgImage").attr("src",  data.BgImage)
                        }
                    });
                },
                yes: function (index, layero) {
                    var submit = $("#btnSubmit2");

                    //监听提交
                    layui.form.on("submit(btnSubmit2)", function (formdata) {
                        var load = layer.msg('正在处理，请稍候', { icon: 16, time: 0, shade: [0.3, '#393D49'] });

                        lobsterlayui.POST('/admin/v1/worker/SaveWorkerStyle', formdata.field).then(data => {
                            layer.msg("保存成功");
                            layer.close(index); //关闭弹层
                            self.data.tablework.reload();
                        });
                    });
                    submit.trigger("click");
                },
            });
        },
        stopworker(data) {
            var self = this;
            // 启用停用机构
            var confirm_msg = "";
            var status = 0;
            if (data.DelFlag == 0) {
                confirm_msg = "确认停用么?";
                status = 1;
            }
            else {
                confirm_msg = "确认启用么?";
                status = 0;
            }

            layer.confirm(confirm_msg, { icon: 3, title: "提示" },
                function (index) {

                    lobsterlayui.GET('/admin/v1/worker/StopWorker', { workid: data.WorkId, delflag: status }).then(data => {
                        layer.close(index);
                        self.data.tablework.reload();
                    }).catch(res => {
                        layer.msg(res.msg);
                        layer.close(index);
                    })
                });
        },
        saveworker(data) {
            var self = this;
            var field = data.field;
            var load = layer.msg('正在处理，请稍候', { icon: 16, time: 0, shade: [0.3, '#393D49'] });

            if (field.WorkId > 0) {
                layer.confirm('确认修改机构信息吗？若修改机构名称，将导致注册码失效，请联系管理员重新注册！！！', { icon: 3, title: '提示' }, function (index) {
                    
                    lobsterlayui.POST('/admin/v1/worker/SaveWorker', field).then(data => {
                        layer.msg("保存成功");
                        layer.closeAll();
                        self.data.tablework.reload();
                    }).catch(res => {
                        layer.msg(res.msg);
                        layer.closeAll();
                    });
                });
            } else {
                lobsterlayui.POST('/admin/v1/worker/SaveWorker', field).then(data => {
                    layer.msg("保存成功");
                    layer.closeAll();
                    self.data.tablework.reload();
                }).catch(res => {
                    layer.msg(res.msg);
                    layer.closeAll();
                });
            }
            
        },
        InitUpload() {
            var upload = layui.upload;
            //初始化通用图片上传组件   
            upload.render({
                elem: '#uploadPicPath',
                url: "/basic/v1/OSS/UploadFile",
                choose: function (obj) {
                    obj.preview(function (index, file, result) {
                        $('#imgPicPath').attr("src", result);
                    });
                },
                done: function (res) {
                    $("#imgPicPath").attr('src', res.data.url);
                    $('#textPicPath').val(res.data.url);
                }
            });
            //初始化平台顶部Logo上传组件
            upload.render({
                elem: '#uploadOpenTopLogo',
                url: "/basic/v1/OSS/UploadFile",
                choose: function (obj) {
                    obj.preview(function (index, file, result) {
                        $("#openTopLogo").val(result);
                        $('#openTopLogo').attr("src", result);
                    });
                },
                done: function (res) {
                    $("#openTopLogo").attr('src', res.data.url);
                    $('#textOpenTopLogo').val(res.data.url);
                }
            });
            //初始化平台欢迎页上传组件
            upload.render({
                elem: '#uploadBgImage',
                url: "/basic/v1/OSS/UploadFile",
                choose: function (obj) {
                    obj.preview(function (index, file, result) {
                        $("#bgImage").val(result);
                        $('#bgImage').attr("src", result);
                    });
                },
                done: function (res) {
                    $("#bgImage").attr('src', res.data.url);
                    $('#textBgImage').val(res.data.url)
                }
            });
            //初始化患者小程序登录页上传组件
            upload.render({
                elem: "#uploadPatientLogo",
                url: "/basic/v1/OSS/UploadFile",
                choose: function (obj) {
                    obj.preview(function (index, file, result) {
                        $("#patientLogo").val(result);
                        $('#patientLogo').attr("src", result);
                    });
                },
                done: function (res) {

                    $('#patientLogo').attr("src", res.data.url);
                    $("#textPatientLogo").val(res.data.url);
                }
            });
            //初始化医生小程序登录页上传组件
            upload.render({
                elem: "#uploadDoctorLogo",
                url: "/basic/v1/OSS/UploadFile",
                choose: function (obj) {
                    obj.preview(function (index, file, result) {
                        $("#doctorLogo").val(result);
                        $('#doctorLogo').attr("src", result);
                    });
                },
                done: function (res) {
                    $('#doctorLogo').attr("src", res.data.url); //图片链接
                    $("#textDoctorLogo").val(res.data.url);  //隐藏值域
                }
            });
        }
    });
</script>

<script type="text/html" id="barRowWorkers">
    <a class="layui-btn layui-btn-xs" lay-event="alter"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="alterstyle"><i class="layui-icon layui-icon-set"></i>设置样式</a>
    {{# if(d.DelFlag==0){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="disable"><i class="layui-icon layui-extend-stop"></i>停用</a>
    {{# } else { }}
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="enable"><i class="layui-icon layui-icon-ok"></i>启用</a>
    {{# } }}
</script>
<script type="text/html" id="barRowWorkType">
    {{# if(d.WorkType==0){ }}
    <span style="color:red">生产机构</span>
    {{# } else if(d.WorkType==1){ }}
    <span>开发机构</span>
    {{# } else { }}
    <span>测试机构</span>
    {{# } }}
</script>
<script type="text/html" id="barRowStates">
    {{# if(d.DelFlag==1){ }}
    <span style="color:red">{{d.States}}</span>
    {{# } else { }}
    <span>{{d.States}}</span>
    {{# } }}
</script>
<script type="text/html" id="barWorkers">
    <a class="layui-btn layui-btn-sm" lay-event="add-submit" id="add"><i class="layui-icon layui-icon-add-1"></i>注册机构</a>
</script>

<script type="text/html" id="dlg_workerform">
    <div class="layui-fluid box">
        <form class="layui-form" lay-filter="formWorkers" id="formWorkers">
            <div class="layui-card">
                <div class="layui-card-body box" id="workdetail">
                    <div class="layui-row">
                        <div class="layui-hide">
                            <input type="text" id="txtWorkId" name="WorkId" value="0" />
                            <input type="text" id="txtDelFlag" name="DelFlag" value="0" />
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-form-item">
                                <label class="layui-form-label"><i style="color:red;">*&ensp; </i>机构名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="WorkName" id="txtWorkName" class="layui-input" required lay-verify="required" style="position:absolute;z-index:2" autocomplete="off">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">机构标识</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" id="txtWorkCode" name="WorkNo" maxlength="30" />
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-form-item">
                                <label class="layui-form-label"><i style="color:red;">*&ensp; </i>统一社会信用码</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" required lay-verify="required" id="txtUnifiedSocialCreditCode" name="UnifiedSocialCreditCode" maxlength="30" />
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">机构注册码</label>
                                <div class="layui-input-block">
                                    <input type="text" name="RegKey" id="txtRegKey" class="layui-input" style="position:absolute;z-index:2" autocomplete="off">
                                    
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-form-item">
                                <label class="layui-form-label"></label>
                                <div class="layui-input-block">
                                    <label>注册机构时，如果为空则默认生成免费30天试用注册码</label>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">备注</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" id="txtMemo" name="Memo" maxlength="500" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item layui-hide">
                        <input type="button" lay-submit lay-filter="btnSubmit" id="btnSubmit" value="保存">
                        <input type="reset" id="LAY-work-form-reset" value="重置">
                    </div>
                </div>
            </div>
        </form>
    </div>
</script>

<script type="text/html" id="dlg_workerstyles">
    <div class="layui-fluid box">
        <form class="layui-form" lay-filter="formWorkerStyles" id="formWorkerStyles">
            <div class="layui-card ">
                <div class="layui-card-body box">
                    <div class="layui-form-item layui-hide">
                        <input type="text" id="textWorkId" name="WorkId" value="0" />
                        <input type="text" id="textID" name="ID" value="0" />
                    </div>
                    <div class="layui-row">

                        <div class="layui-col-xs4">
                            <div class="layui-form-item">
                                <label class="layui-form-label">平台顶部LOGO</label>
                                <div class="layui-input-block">
                                    <div class="layui-upload">
                                        <button type="button" class="layui-btn" id="uploadOpenTopLogo">选择图片</button>
                                        <div class="layui-upload-list">
                                            <img class="layui-upload-img" src="~/resource/service.jpg" id="openTopLogo" style="width:90px; height:90px">
                                        </div>
                                        <div class="layui-hide">
                                            <input type="text" id="textOpenTopLogo" name="OpenTopLogo" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs4">
                            <div class="layui-form-item">
                                <label class="layui-form-label">平台欢迎页图片</label>
                                <div class="layui-input-block">
                                    <div class="layui-upload">
                                        <button type="button" class="layui-btn" id="uploadBgImage">选择图片</button>
                                        <div class="layui-upload-list">
                                            <img class="layui-upload-img" src="~/resource/service.jpg" id="bgImage" style="width:90px; height:90px">
                                        </div>
                                        <div class="layui-hide">
                                            <input type="text" id="textBgImage" name="BgImage" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs4">
                            <div class="layui-form-item">
                                <label class="layui-form-label">患者小程序登录页</label>
                                <div class="layui-input-block">
                                    <div class="layui-upload">
                                        <button type="button" class="layui-btn" id="uploadPatientLogo">选择图片</button>
                                        <div class="layui-upload-list">
                                            <img class="layui-upload-img" src="~/resource/service.jpg" id="patientLogo" style="width:90px; height:90px">
                                        </div>
                                        <div class="layui-hide">
                                            <input type="text" id="textPatientLogo" name="PatientLogo" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs4">
                            <div class="layui-form-item">
                                <label class="layui-form-label">医生小程序登录页</label>
                                <div class="layui-input-block">
                                    <div class="layui-upload">
                                        <button type="button" class="layui-btn" id="uploadDoctorLogo">选择图片</button>
                                        <div class="layui-upload-list">
                                            <img class="layui-upload-img" src="~/resource/service.jpg" id="doctorLogo" style="width:90px; height:90px">
                                        </div>
                                        <div class="layui-hide">
                                            <input type="text" id="textDoctorLogo" name="DoctorLogo" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">患者端文字</label>
                                <div class="layui-input-block">
                                    <input type="text" required lay-verify="required" class="layui-input" id="textPatientText" name="PatientText" />
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">医生端文字</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" required lay-verify="required" id="textDoctorText" name="DoctorText" />
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">平台顶部文字</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" required lay-verify="required" id="textOpenTopText" name="OpenTopText" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item layui-hide">
                        <input type="button" lay-submit lay-filter="btnSubmit2" id="btnSubmit2" value="确认">
                    </div>
                </div>
            </div>
        </form>
    </div>
</script>
